Skip to content

OutOfProcessIPythonWidget

Base classes

Name Children Inherits
BaseIPythonWidget
prettyqt.ipython.baseipythonwidget
Convenience class for a live IPython console widget running out-of-process.

⋔ Inheritance diagram

graph TD
  418218929["ipython.OutOfProcessIPythonWidget"]
  412360768["ipython.BaseIPythonWidget"]
  548562404["rich_jupyter_widget.RichJupyterWidget"]
  3893578720["rich_jupyter_widget.RichIPythonWidget"]
  2577579137["jupyter_widget.JupyterWidget"]
  1359188613["jupyter_widget.IPythonWidget"]
  1600289359["frontend_widget.FrontendWidget"]
  4247442520["history_console_widget.HistoryConsoleWidget"]
  330948184["console_widget.ConsoleWidget"]
  831903233["util.NewBase"]
  3806155832["configurable.LoggingConfigurable"]
  1666290838["configurable.Configurable"]
  2478326197["traitlets.HasTraits"]
  2674025753["traitlets.HasDescriptors"]
  2751680898["builtins.object"]
  1089529877["util.SuperQClass"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  1685905456["base_frontend_mixin.BaseFrontendMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  625385617["gui.PaintDeviceMixin"]
  412360768 --> 418218929
  548562404 --> 412360768
  3893578720 --> 548562404
  2577579137 --> 3893578720
  1359188613 --> 2577579137
  1600289359 --> 1359188613
  4247442520 --> 1600289359
  330948184 --> 4247442520
  831903233 --> 330948184
  3806155832 --> 831903233
  1666290838 --> 3806155832
  2478326197 --> 1666290838
  2674025753 --> 2478326197
  2751680898 --> 2674025753
  1089529877 --> 831903233
  3620195106 --> 1089529877
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333
  1685905456 --> 1600289359
  2751680898 --> 1685905456
  829357528 --> 412360768
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528

🛈 DocStrings

Bases: BaseIPythonWidget

Convenience class for a live IPython console widget running out-of-process.

Source code in prettyqt/ipython/outofprocessipythonwidget.py
class OutOfProcessIPythonWidget(ipython.BaseIPythonWidget):
    """Convenience class for a live IPython console widget running out-of-process."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        temp_path = core.Dir.get_temp_path()
        self.connection_file = temp_path / f"connection-{os.getpid()}.json"
        self.p = multiprocessing.Process(target=run_server, args=(self.connection_file,))
        self.p.daemon = True
        self.p.start()
        logger.info("waiting for connection file creation....")
        for _ in range(500):
            if self.connection_file.exists() and self.connection_file.stat().st_size > 0:
                break
            widgets.Application.sleep(0.1)
        else:
            raise FileNotFoundError(self.connection_file)
        logger.info("Connection file found. Opening channels.")
        kernel_client = QtKernelClient(connection_file=os.fspath(self.connection_file))
        kernel_client.load_connection_file()  # can throw FileNotFoundError
        kernel_client.start_channels()
        self.kernel_client = kernel_client

    def shutdown(self):
        """Stop IPython server process and clean up."""
        logger.info("shutting down IPython MP kernel")
        assert self.kernel_client, "Kernel client not initialized"
        self.kernel_client.stop_channels()
        self.kernel_client.shutdown()
        self.p.terminate()
        self.connection_file.unlink(missing_ok=True)
        logger.info("shutdown successful.")

shutdown()

Stop IPython server process and clean up.

Source code in prettyqt/ipython/outofprocessipythonwidget.py
def shutdown(self):
    """Stop IPython server process and clean up."""
    logger.info("shutting down IPython MP kernel")
    assert self.kernel_client, "Kernel client not initialized"
    self.kernel_client.stop_channels()
    self.kernel_client.shutdown()
    self.p.terminate()
    self.connection_file.unlink(missing_ok=True)
    logger.info("shutdown successful.")

:fa-brands-github: Show source on GitHub